home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Graphics / GifScan 1.6 / Sources / Lib Sources / DropShellSIOUX.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-13  |  7.4 KB  |  345 lines  |  [TEXT/MMCC]

  1. /******************************************************************************
  2. **
  3. **  Project Name:    DropShell
  4. **     File Name:    DropShell.c
  5. **
  6. **   Description:    Main application code for the QuickShell
  7. **
  8. *******************************************************************************
  9. **                       A U T H O R   I D E N T I T Y
  10. *******************************************************************************
  11. **
  12. **    Initials    Name
  13. **    --------    -----------------------------------------------
  14. **    LDR            Leonard Rosenthol
  15. **    MTC            Marshall Clow
  16. **    SCS            Stephan Somogyi
  17. **
  18. *******************************************************************************
  19. **                      R E V I S I O N   H I S T O R Y
  20. *******************************************************************************
  21. **
  22. **      Date        Author    Description
  23. **    ---------    ------    ---------------------------------------------
  24. **    23 Jun    94    LDR        Implemented support for disk insertion events
  25. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  26. **                        Removed the ResumeProc as per new Apple recommendations
  27. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  28. **                        Skipped System 6 compatible rev of DropShell source
  29. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  30. **                        Quit now sends AEVT to self to be politically correct
  31. **                        Added support for the new gSplashScreen
  32. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  33. **    29 Oct 91    SCS        Changes for THINK C 5
  34. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  35. **                        Added a bunch of comments for clarification
  36. **    06 Oct 91    MTC        Converted to MPW C
  37. **    09 Apr 91    LDR        Added to Projector
  38. **
  39. ******************************************************************************/
  40.  
  41. #include "GifScan.h"
  42. #ifdef ___USE_SIOUX___
  43.  
  44. #ifndef __MWERKS__
  45. #include <Desk.h>
  46. #include <Dialogs.h>
  47. #include <Errors.h>
  48. #include <Files.h>
  49. #include <Fonts.h>
  50. #include <Memory.h>
  51. #include <Menus.h>
  52. #include <StandardFile.h>
  53. #include <TextEdit.h>
  54. #include <Types.h>
  55. #include <Windows.h>
  56. #endif
  57.  
  58. #include "DSGlobals.h"
  59. #include "DSUserProcs.h"
  60. #include "DSAppleEvents.h"
  61.  
  62. #include "DropShell.h"
  63.  
  64. #include <SIOUX.h>
  65.  
  66. #include "Prefs.h"
  67.  
  68. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent, gCmdHeldDown;
  69. EventRecord    gEvent;
  70. MenuHandle    gAppleMenu, gFileMenu, gEditMenu;
  71. WindowPtr    gSplashScreen;
  72.  
  73. #ifdef MPW
  74. extern void _DataInit();    
  75. #endif
  76.  
  77. void InitToolbox (void) 
  78. {
  79.  
  80. #ifdef MPW
  81.     UnloadSeg ((Ptr) _DataInit );
  82. #endif
  83.  
  84.     InitGraf ( &qd.thePort );
  85.     InitFonts ();
  86.     InitWindows ();
  87.     InitMenus ();
  88.     TEInit ();
  89.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  90.     InitCursor ();
  91.     FlushEvents ( everyEvent, 0 );
  92.     
  93.     // how about some memory fun! Two should be enough!
  94.     MoreMasters ();
  95.     MoreMasters ();
  96.     }
  97.  
  98. /*
  99.     Let's setup those global variables that the DropShell uses.
  100.     
  101.     If you add any globals for your own use,
  102.     init them in the InitUserGlobals routine in DSUserProcs.c
  103. */
  104.  
  105. Boolean InitGlobals (void) 
  106. {
  107.     long aLong;
  108.  
  109.     gDone            = false;
  110.     gOApped            = false;    // probably not since users are supposed to DROP things!
  111.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  112.     gSplashScreen    = NULL;
  113.  
  114.     return(InitUserGlobals());    // call the user proc
  115. }
  116.  
  117. /*
  118.     Again, nothing fancy.  Just setting up the menus.
  119.     
  120.     If you add any menus to your DropBox - insert them here!
  121. */
  122.  
  123. void SetUpMenus (void) 
  124. {
  125.     gAppleMenu = GetMenu ( kAppleNum );
  126.     AppendResMenu ( gAppleMenu, 'DRVR' );
  127.     InsertMenu ( gAppleMenu, 0 );
  128.  
  129.     gFileMenu = GetMenu ( kFileNum );
  130.     InsertMenu ( gFileMenu, 0 );
  131.     
  132.     gEditMenu = GetMenu ( kEditNum );
  133.     InsertMenu(gEditMenu, 0);
  134.     
  135.     DrawMenuBar ();
  136. }
  137.  
  138.  
  139. /*    --------------- Standard Event Handling routines ---------------------- */
  140.  
  141. void ShowAbout ( void ) 
  142. {
  143.     (void) Alert ( 128, NULL );
  144.     
  145. }
  146.  
  147. void DoMenu ( long retVal ) 
  148. {
  149.     short            menuID, itemID;
  150.     Str255            itemStr;
  151.     EventRecord        dummyEvent;
  152.  
  153.     menuID = HiWord ( retVal );
  154.     itemID = LoWord ( retVal );
  155.     
  156.     switch ( menuID ) {
  157.         case kAppleNum:
  158.             if ( itemID == 1 )
  159.                 ShowAbout ();    /*    Show the about box */
  160.             else
  161.             {
  162.                 GetMenuItemText(GetMenuHandle(kAppleNum), itemID, itemStr);
  163.                 OpenDeskAcc(itemStr);
  164.             }
  165.             break;
  166.             
  167.         case kFileNum:
  168.             switch (itemID)
  169.             {
  170.                 case 1:
  171.                     SelectFile();    // call file selection userProc
  172.                     break;
  173.                 
  174.                 case 2:        /* Save As */
  175.                 
  176.                     /* Fake a key event for SIOUX */
  177.                     dummyEvent.what = keyDown;
  178.                     dummyEvent.modifiers = cmdKey;
  179.                     dummyEvent.message = 's' & charCodeMask;
  180.                     SIOUXHandleOneEvent(&dummyEvent);
  181.                     break;
  182.                     
  183.                 case 3:        /* Preferences */
  184.                     SetPreferences();
  185.                     break;
  186.                 
  187.                 default:
  188.                     SendQuitToSelf();    // send self a 'quit' event
  189.                     break;
  190.             }
  191.             break;
  192.         
  193.         case kEditNum:
  194.             dummyEvent.what = keyDown;
  195.             dummyEvent.modifiers = cmdKey;
  196.             switch (itemID)
  197.             {
  198.                 case 3:        /* Cut */
  199.                     dummyEvent.message = 'x' & charCodeMask;
  200.                     break;
  201.                     
  202.                 case 4:        /* Copy */
  203.                     dummyEvent.message = 'c' & charCodeMask;
  204.                     break;
  205.                 
  206.                 case 5:        /* Paste */
  207.                     dummyEvent.message = 'v' & charCodeMask;
  208.                     break;
  209.                 
  210.                 case 6:        /* Select All */
  211.                     dummyEvent.message = 'a' & charCodeMask;
  212.                     break;
  213.             }
  214.  
  215.             SIOUXHandleOneEvent(&dummyEvent);
  216.             break;
  217.             
  218.         default:
  219.             break;
  220.             
  221.         }
  222.     HiliteMenu(0);        // turn it off!
  223. }
  224.  
  225. void DoMouseDown ( EventRecord *curEvent ) 
  226. {
  227.     WindowPtr    whichWindow;
  228.     short        whichPart;
  229.  
  230.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  231.     switch ( whichPart ) 
  232.     {
  233.         case inMenuBar:
  234.             DoMenu ( MenuSelect ( curEvent->where ));
  235.             break;
  236.         
  237.         case inSysWindow:
  238.             SystemClick ( curEvent, whichWindow );
  239.             break;
  240.         
  241.         case inDrag:
  242.             {
  243.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  244.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  245.             }
  246.         default:
  247.             break;
  248.         }
  249.     }
  250.  
  251.  
  252.  
  253. void DoKeyDown ( EventRecord *curEvent ) 
  254. {
  255.     char    theKey;
  256.     short    i;
  257.     char     commandEdits[] =  { 'X', 'V', 'C', 'A', 'x', 'v', 'c', 'a', 'S', 's' };
  258.     Boolean    alreadyHandled = false;
  259.  
  260.     theKey = (char) curEvent->message & charCodeMask;
  261.     
  262.     if ( curEvent->modifiers & cmdKey )
  263.     {
  264.         /* Must do something to handle the SIOUX window commands, 
  265.            filter those commands out. */
  266.         for (i = 0; i < sizeof(commandEdits) / sizeof(char); i++) 
  267.         {
  268.             if ( theKey == commandEdits[i] )
  269.                 alreadyHandled = true;
  270.         }
  271.         if ( !alreadyHandled ) DoMenu ( MenuKey (theKey));
  272.     }
  273. }
  274.  
  275.  
  276.  
  277.  
  278. void main ( void ) 
  279. {
  280.     Boolean        SIOUXDidEvent;
  281.     
  282.     InitToolbox ();
  283.     
  284.     if ( InitGlobals () ) 
  285.     {    
  286.         // if we succeeding in initting self
  287.         if ( !gHasAppleEvents )
  288.         {
  289.             ErrorAlert ( kErrStringID, kCantRunErr, 0, true );
  290.         }
  291.         else
  292.         {
  293.             InitAEVTStuff ();
  294.             SetUpMenus ();
  295.             
  296.             while ( !gDone ) 
  297.             {
  298.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  299.                 
  300.                 if ( gWasEvent )
  301.                 {
  302.                     /* Let SIOUX handle the event first */
  303.                     SIOUXDidEvent = SIOUXHandleOneEvent(&gEvent);
  304.                 }
  305.                  
  306.                 if ( !SIOUXDidEvent )
  307.                 {
  308.                     switch ( gEvent.what ) 
  309.                     {
  310.                         case kHighLevelEvent:
  311.                             DoHighLevelEvent ( &gEvent );
  312.                             break;
  313.                             
  314.                         case mouseDown:
  315.                             DoMouseDown ( &gEvent );
  316.                             break;
  317.                             
  318.                         case keyDown:
  319.                         case autoKey:
  320.                             DoKeyDown ( &gEvent );
  321.                             break;
  322.  
  323.                         case diskEvt:
  324.                             if (HiWord(gEvent.message)) 
  325.                             {
  326.                                 Point diskInitPt;
  327.                                 
  328.                                 diskInitPt.v = diskInitPt.h = 100;
  329.                                 DILoad();
  330.                                 DIBadMount(diskInitPt, gEvent.message);
  331.                                 DIUnload();
  332.                             }
  333.                             break;
  334.                             
  335.                         default:
  336.                             break;
  337.                         }
  338.                     }
  339.                 }
  340.             }
  341.         }
  342.     DisposeUserGlobals();    // call the userproc to clean itself up
  343. }
  344.  
  345. #endif